/**
 * Created by SunLunatic on 2015/4/5.
 */
var data =[
    {"_children":
        [{"_children":[
            {"_value":"蓝楹","id":"5"},
            {"_value":"火烧花","id":"6"},
            {"_value":"木蝴蝶","id":"7", "disabled":"true"}],
            "_value":"紫葳科","id":"3"},
            {"_children":[
                {"_value":"紫草","id":"8"},
                {"_value":"勿忘我","id":"9"}],
                "_value":"紫草科","id":"4"}],
        "_value":"管花目","id":"1"},
    {"_children":
        [{"_value":"石蒜科","id":"10"}],
        "_value":"天门冬目","id":"2"}
];
var opts = {
    data: data,
    children: "_children",
    text: "_value"
};
var data2 = [{"name":"东部王国", id:"1", leaf:"false"},
    {"name":"卡里姆多", id:"2", leaf:"false"},
    {"name":"诺森德", id:"3", leaf:"false"},
    {"name":"潘达利亚", id:"4"}];
var opts2 = {
    data: data2,
    synac: "/project/loadTree"
};
var opts3 = {
    data: data2,
    synac: "/project/loadTree",
    modal: "checkbox"
};
var opts4 = {
    data: [{"name":"东部王国", id:"1", leaf:"false"},
        {"name":"卡里姆多", id:"2", leaf:"false"},
        {"name":"诺森德", id:"3", leaf:"false"},
        {"name":"潘达利亚", id:"4"}],
    synac: "/project/loadTree",
    modal: "radio"
}


function jcrd(){
    $("#test").jacaranda(opts).jcrdTree.expandAll();
    $("#test2").jacaranda(opts2);
    $("#test3").jacaranda(opts3).on("jcrd.choose.after", function(event, id, isSelected, $dom){
        if(isSelected)alert("选中了"+$dom.text());
    });
    $("#test4").jacaranda(opts4).on("jcrd.unChecked.after", function(event, id, $dom){
        alert($dom.text()+"失去了选中状态");
    });
}
$(document).ready(function (){
    $("#jacarandaMenu").addClass("ya-music-listening");
    $(".ya-head").on("click", ".ya-label", changeLabel);
    jcrd();
});
function changeLabel(event){
    var $this = $(event.currentTarget);
    if($this.hasClass("ya-active"))return;
    var $nowActive =  $($this.parent().children(".ya-active")[0]);
    $nowActive.removeClass("ya-active");
    $("#"+$nowActive.attr("data-val")).addClass("ya-hide");
    $this.addClass("ya-active");
    $("#"+$this.attr("data-val")).removeClass("ya-hide");
}
